package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TbInstitutionMapper;
import com.ruoyi.system.domain.TbInstitution;
import com.ruoyi.system.service.ITbInstitutionService;

/**
 * 机构表Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-18
 */
@Service
public class TbInstitutionServiceImpl implements ITbInstitutionService 
{
    @Autowired
    private TbInstitutionMapper tbInstitutionMapper;
    @Autowired
    private StringHttpMessageConverter stringHttpMessageConverter;

    /**
     * 查询机构表
     * 
     * @param institutionCode 机构表主键
     * @return 机构表
     */
    @Override
    public TbInstitution selectTbInstitutionByInstitutionCode(String institutionCode)
    {
        return tbInstitutionMapper.selectTbInstitutionByInstitutionCode(institutionCode);
    }

    /**
     * 查询机构表列表
     * 
     * @param tbInstitution 机构表
     * @return 机构表
     */
    @Override
    public List<TbInstitution> selectTbInstitutionList(TbInstitution tbInstitution)
    {
        return tbInstitutionMapper.selectTbInstitutionList(tbInstitution);
    }

    /**
     * 新增机构表
     * 
     * @param tbInstitution 机构表
     * @return 结果
     */
    @Override
    public int insertTbInstitution(TbInstitution tbInstitution)
    {
        //先查询最大字段
        String maxIDing = tbInstitutionMapper.selectMaxID();//查询数据库的最大id
        if (maxIDing == null){
            maxIDing = "institution_1";
            tbInstitution.setInstitutionCode(maxIDing);
        }else {
            String maxID = maxIDing.substring(12);//截取后面的数字
            int maxIDint = Integer.parseInt(maxID);
            maxIDint++;
            maxID = "institution_"+maxIDint;
            tbInstitution.setInstitutionCode(maxID);
        }
        return tbInstitutionMapper.insertTbInstitution(tbInstitution);
    }

    /**
     * 修改机构表
     * 
     * @param tbInstitution 机构表
     * @return 结果
     */
    @Override
    public int updateTbInstitution(TbInstitution tbInstitution)
    {
        return tbInstitutionMapper.updateTbInstitution(tbInstitution);
    }

    /**
     * 批量删除机构表
     * 
     * @param institutionCodes 需要删除的机构表主键
     * @return 结果
     */
    @Override
    public int deleteTbInstitutionByInstitutionCodes(String[] institutionCodes)
    {
        return tbInstitutionMapper.deleteTbInstitutionByInstitutionCodes(institutionCodes);
    }

    /**
     * 删除机构表信息
     * 
     * @param institutionCode 机构表主键
     * @return 结果
     */
    @Override
    public int deleteTbInstitutionByInstitutionCode(String institutionCode)
    {
        return tbInstitutionMapper.deleteTbInstitutionByInstitutionCode(institutionCode);
    }

}
